<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>使用 reviver 函数解析日期</title>
</head>

<body>
    <h1>把字符串转换为 date 对象</h1>
    <p id="demo"></p>
    <script>
        var text = '{"name":"Bill Gates", "birth":"1955-10-28", "city":"Seattle"}';
        var obj = JSON.parse(text, function (key, value) {
            if (key == "birth") {
                return new Date(value);
            } else {
                return value;
            }
        });
        document.getElementById("demo").innerHTML = obj.name + ", " + obj.birth;
    </script>
</body>

</html>